package org.example.struct.array;

/**
 * @author liyishan
 * @date 2024/6/20 10:29
 * @apiNote
 */

public class Test02748VCountBeautifulPairs {

    public static void main(String[] args) {

    }

    public int countBeautifulPairs(int[] nums) {
        int count = 0;
        for (int i = 0; i < nums.length; i++) {
            for (int j = i + 1; j < nums.length; j++) {
                if (gcd(firstNum(nums[i]), nums[j] % 10) == 1) {
                    count++;
                }
            }
        }
        return count;
    }


    private static int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    private static int firstNum(int num) {
        while (num >= 10) {
            num = num / 10;
        }
        return num;
    }
}
